package cn.hfjava.kz.controller;


import cn.dev33.satoken.util.SaResult;
import cn.hfjava.kz.entity.po.Permission;
import cn.hfjava.kz.service.PermissionService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/api/v1/perms")
@Tag(name = "菜单权限管理模块")
public class PermissionController {

    @Resource
    private PermissionService permissionService;

    @GetMapping("/tree")
    @Operation(summary = "获取权限树数据")
    public SaResult tableTree(){
        List<Permission> permsList = permissionService.findAllPermission();
        List<Permission> permsTreeList = permissionService.buildPermissionTree(permsList);
        return SaResult.data(permsTreeList);
    }


    /**
     * 获取权限树数据
     * @return
     */
    @Operation(summary = "获取权限树数据")
    @GetMapping("/menuTree")
    public SaResult menuTree(){
        List<Permission> permList = permissionService.listWithTree();
        return SaResult.data(permList);
    }


}
